package com.jy.oms.framework.asyn.task.web;

import com.jy.oms.framework.asyn.task.constants.TaskStateEnum;
import com.jy.oms.framework.asyn.task.queue.database.entity.SysTaskQueue;
import com.jy.oms.framework.util.DateUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

/**
 * 任务vo
 *
 * @author liuquan
 */
public class TaskQueueVo {

    private String id;

    /**
     * 任务编码
     */
    private String taskCode;

    /**
     * 任务参数
     */
    private String taskParam;

    /**
     * 执行次数
     */
    private Integer callCount;

    /**
     * 相关单号
     */
    private String billCode;

    /**
     * 状态，0待处理，1已处理
     */
    private Integer state;

    /**
     * 任务最早执行时间
     */
    private Date earliestExecuteTime;

    private String earliestExecuteTimeStr;

    private String uuid;

    private Date createDate;

    private String createDateStr;

    private Date updateDate;

    private String taskQueueName;

    public static TaskQueueVo convertSysTaskQueue(SysTaskQueue sysTaskQueue){
        return new TaskQueueVo()
                .setId(sysTaskQueue.getId().toString())
                .setTaskCode(sysTaskQueue.getTaskCode())
                .setTaskParam(sysTaskQueue.getTaskParam())
                .setCallCount(sysTaskQueue.getCallCount())
                .setBillCode(StringUtils.defaultString(sysTaskQueue.getBillCode(), ""))
                .setState(TaskStateEnum.between(sysTaskQueue.getState(), TaskStateEnum.UNDO, TaskStateEnum.DONE)
                        ? sysTaskQueue.getState() : TaskStateEnum.ERROR.getCode()) //前端状态为2时表示失败状态
                .setUuid(sysTaskQueue.getUuid())
                .setEarliestExecuteTime(sysTaskQueue.getEarliestExecuteTime())
                .setEarliestExecuteTimeStr(DateUtils.date2String(sysTaskQueue.getEarliestExecuteTime(), "yyyy-MM-dd HH:mm:ss"))
                .setCreateDate(sysTaskQueue.getCreateDate())
                .setCreateDateStr(DateUtils.date2String(sysTaskQueue.getCreateDate(), "yyyy-MM-dd HH:mm:ss"))
                .setUpdateDate(sysTaskQueue.getUpdateDate());
    }

    public String getId() {
        return id;
    }

    public TaskQueueVo setId(String id) {
        this.id = id;
        return this;
    }

    public String getTaskCode() {
        return taskCode;
    }

    public TaskQueueVo setTaskCode(String taskCode) {
        this.taskCode = taskCode;
        return this;
    }

    public String getTaskParam() {
        return taskParam;
    }

    public TaskQueueVo setTaskParam(String taskParam) {
        this.taskParam = taskParam;
        return this;
    }

    public Integer getCallCount() {
        return callCount;
    }

    public TaskQueueVo setCallCount(Integer callCount) {
        this.callCount = callCount;
        return this;
    }

    public String getBillCode() {
        return billCode;
    }

    public TaskQueueVo setBillCode(String billCode) {
        this.billCode = billCode;
        return this;
    }

    public Integer getState() {
        return state;
    }

    public TaskQueueVo setState(Integer state) {
        this.state = state;
        return this;
    }

    public Date getEarliestExecuteTime() {
        return earliestExecuteTime;
    }

    public TaskQueueVo setEarliestExecuteTime(Date earliestExecuteTime) {
        this.earliestExecuteTime = earliestExecuteTime;
        return this;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public TaskQueueVo setCreateDate(Date createDate) {
        this.createDate = createDate;
        return this;
    }

    public Date getUpdateDate() {
        return updateDate;
    }

    public TaskQueueVo setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
        return this;
    }

    public String getTaskQueueName() {
        return taskQueueName;
    }

    public TaskQueueVo setTaskQueueName(String taskQueueName) {
        this.taskQueueName = taskQueueName;
        return this;
    }

    public String getEarliestExecuteTimeStr() {
        return earliestExecuteTimeStr;
    }

    public TaskQueueVo setEarliestExecuteTimeStr(String earliestExecuteTimeStr) {
        this.earliestExecuteTimeStr = earliestExecuteTimeStr;
        return this;
    }

    public String getCreateDateStr() {
        return createDateStr;
    }

    public TaskQueueVo setCreateDateStr(String createDateStr) {
        this.createDateStr = createDateStr;
        return this;
    }

    public String getUuid() {
        return uuid;
    }

    public TaskQueueVo setUuid(String uuid) {
        this.uuid = uuid;
        return this;
    }
}
